#include "viewPanel.h"
#include "defines/view.h"

#include <iostream>

ViewPanel::ViewPanel(QWidget* _parent) : QWidget(_parent){
    viewObjectRadio = new QRadioButton(tr("Normal"));
    QRadioButton *wireframeObjectRadio = new QRadioButton(tr("Wireframe"));
//    QRadioButton *notViewObjectRadio = new QRadioButton(QString::fromUtf8("Não visualizar"));
    viewObjectRadio->setChecked(true);

    connect(viewObjectRadio, SIGNAL(toggled(bool)), this, SLOT(viewObjectRadioToggled(bool)));
    connect(wireframeObjectRadio, SIGNAL(toggled(bool)), this, SLOT(wireframeObjectRadioToggled(bool)));


    QVBoxLayout *objectLayout = new QVBoxLayout;
	objectLayout->addWidget(viewObjectRadio);
	objectLayout->addWidget(wireframeObjectRadio);
//	objectLayout->addWidget(notViewObjectRadio);
//	objectLayout->addStretch(0);

	objectGroupBox = new QGroupBox(tr("Objetos"));
	objectGroupBox->setLayout(objectLayout);



    QRadioButton *fillOctreeRadio = new QRadioButton(tr("Normal"));
    QRadioButton *wireframeOctreeRadio = new QRadioButton(tr("Wireframe"));
    QCheckBox *borderOctreeCheckBox = new QCheckBox(QString::fromUtf8("Bordas"));
    fillOctreeRadio->setChecked(true);

    connect(fillOctreeRadio, SIGNAL(toggled(bool)), this, SLOT(fillOctreeRadioToggled(bool)));
    connect(wireframeOctreeRadio, SIGNAL(toggled(bool)), this, SLOT(wireframeOctreeRadioToggled(bool)));
    connect(borderOctreeCheckBox, SIGNAL(clicked(bool)), this, SLOT(viewOctreeBorderCheckBoxChecked(bool)));


    QVBoxLayout *octreeLayout = new QVBoxLayout;
	octreeLayout->addWidget(fillOctreeRadio);
	octreeLayout->addWidget(wireframeOctreeRadio);
	octreeLayout->addWidget(borderOctreeCheckBox);
//	octreeLayout->addStretch(0);

	octreeGroupBox = new QGroupBox(tr("Octree"));
	octreeGroupBox->setLayout(octreeLayout);
	octreeGroupBox->setDisabled(true);

    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(objectGroupBox);
    layout->addWidget(octreeGroupBox);
	layout->addStretch(1);

    setLayout(layout);
}

ViewPanel::~ViewPanel(){
    delete octreeGroupBox;
    delete viewObjectRadio;
}

void ViewPanel::enableOctree(bool _b){
	octreeGroupBox->setEnabled(_b);
	if(_b){
	    viewObjectRadio->setText(QString::fromUtf8("Não visualizar"));
        if(viewObjectRadio->isChecked()) emit objectViewTypeChanged(OBJECT_NOT_SHOW);
	}
	else{
	    viewObjectRadio->setText("Normal");
        if(viewObjectRadio->isChecked()) emit objectViewTypeChanged(OBJECT_FILL_SHOW);
	}
}

void ViewPanel::viewObjectRadioToggled(bool _b){
//    if(octreeGroupBox->isEnabled()) objectViewType = OBJECT_NOT_SHOW;
//    else objectViewType = OBJECT_FILL_SHOW;
    if(_b){
        if(octreeGroupBox->isEnabled()) emit objectViewTypeChanged(OBJECT_NOT_SHOW);
        else emit objectViewTypeChanged(OBJECT_FILL_SHOW);
    }
}

void ViewPanel::wireframeObjectRadioToggled(bool _b){
    if(_b) emit objectViewTypeChanged(OBJECT_WIREFRAME_SHOW);
}

void ViewPanel::fillOctreeRadioToggled(bool _b){
    if(_b) emit octreeViewTypeChanged(OCTREE_FILL_SHOW);
}

void ViewPanel::wireframeOctreeRadioToggled(bool _b){
    if(_b) emit octreeViewTypeChanged(OCTREE_WIREFRAME_SHOW);
}

void ViewPanel::viewOctreeBorderCheckBoxChecked(bool _b){
    if(_b) emit octreeViewTypeChanged(OCTREE_BORDER_SHOW);
    else emit octreeViewTypeChanged(OCTREE_BORDER_NOT_SHOW);
}

void ViewPanel::onlyOctreeMode(bool _b){
	octreeGroupBox->setDisabled(!_b);
	objectGroupBox->setDisabled(_b);
}
